package gt.edu.usac.viewcontroller.backing.app;

import gt.edu.usac.model.am.AppModuleImpl;

import gt.edu.usac.model.vo.temporadaInscripcionViewImpl;

import gt.edu.usac.viewcontroller.utils.JSFUtils;

import java.util.Calendar;

import javax.faces.component.UISelectItems;
import javax.faces.component.html.HtmlForm;

import javax.faces.component.html.HtmlPanelGrid;

import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCDataControl;
import oracle.adf.view.faces.component.core.data.CoreColumn;
import oracle.adf.view.faces.component.core.data.CoreTable;
import oracle.adf.view.faces.component.core.input.CoreInputText;
import oracle.adf.view.faces.component.core.input.CoreSelectInputDate;
import oracle.adf.view.faces.component.core.input.CoreSelectOneChoice;
import oracle.adf.view.faces.component.core.layout.CorePanelForm;
import oracle.adf.view.faces.component.core.layout.CorePanelTip;
import oracle.adf.view.faces.component.core.nav.CoreCommandButton;
import oracle.adf.view.faces.component.core.nav.CoreCommandLink;
import oracle.adf.view.faces.component.core.output.CoreObjectSpacer;
import oracle.adf.view.faces.component.core.output.CoreOutputLabel;


import oracle.adf.view.faces.component.core.output.CoreOutputText;

import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;

import oracle.jbo.ApplicationModule;
import oracle.jbo.Row;

public class HabilitarTemporada {
    private HtmlForm form1;

    private String valorAno;
    private CorePanelForm panelForm1;
    private HtmlPanelGrid panelGroup2;
    private CoreOutputLabel outputLabel1;
    private CoreSelectInputDate selectInputDate1;
    private CoreSelectInputDate selectInputDate2;
    private CoreSelectInputDate selectInputDate3;
    private CoreSelectInputDate selectInputDate4;
    private CoreSelectInputDate selectInputDate5;
    private CoreObjectSpacer objectSpacer1;
    private CoreObjectSpacer objectSpacer2;
    private CoreSelectOneChoice selectOneChoice1;
    private UISelectItems selectItems1;
    
    private BindingContainer bindings;
    private CoreCommandButton commandButton2;
    private CoreCommandButton commandButton3;
    private CoreInputText outputText1;
    private CoreSelectInputDate selectInputDate6;
    private CoreTable table1;
    private CoreColumn column2;
    private CoreCommandLink outputText3;
    private CoreCommandButton commandButton1;
    private CorePanelTip panelTip1;
    private CoreOutputText outputText10;
    private CorePanelTip panelTip2;
    private CoreOutputText outputText11;
    private CoreColumn column3;
    private CoreOutputText outputText2;
    private CoreColumn column1;
    private CoreOutputText outputText4;
    private CoreColumn column8;
    private CoreOutputText outputText5;
    private CoreColumn column4;
    private CoreOutputText outputText6;
    private CoreColumn column5;
    private CoreOutputText outputText7;
    private CoreColumn column6;
    private CoreOutputText outputText8;
    private CoreColumn column71;
    private CoreOutputText outputText12;
    private CoreColumn column9;
    private CoreCommandLink commandLink1;

    public void setForm1(HtmlForm form1) {
        this.form1 = form1;
    }

    public HtmlForm getForm1() {
        return form1;
    }


    public void setValorAno(String valorAno) {
        this.valorAno = valorAno;
        
    }

    public String getValorAno() {
        this.valorAno = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
        return valorAno;
    }


    public void setPanelForm1(CorePanelForm panelForm1) {
        this.panelForm1 = panelForm1;
    }

    public CorePanelForm getPanelForm1() {
        return panelForm1;
    }


    public void setPanelGroup2(HtmlPanelGrid panelGroup2) {
        this.panelGroup2 = panelGroup2;
    }

    public HtmlPanelGrid getPanelGroup2() {
        return panelGroup2;
    }

    public void setOutputLabel1(CoreOutputLabel outputLabel1) {
        this.outputLabel1 = outputLabel1;
    }

    public CoreOutputLabel getOutputLabel1() {
        return outputLabel1;
    }


    public void setSelectInputDate1(CoreSelectInputDate selectInputDate1) {
        this.selectInputDate1 = selectInputDate1;
    }

    public CoreSelectInputDate getSelectInputDate1() {
        return selectInputDate1;
    }

    public void setSelectInputDate2(CoreSelectInputDate selectInputDate2) {
        this.selectInputDate2 = selectInputDate2;
    }

    public CoreSelectInputDate getSelectInputDate2() {
        return selectInputDate2;
    }

    public void setSelectInputDate3(CoreSelectInputDate selectInputDate3) {
        this.selectInputDate3 = selectInputDate3;
    }

    public CoreSelectInputDate getSelectInputDate3() {
        return selectInputDate3;
    }

    public void setSelectInputDate4(CoreSelectInputDate selectInputDate4) {
        this.selectInputDate4 = selectInputDate4;
    }

    public CoreSelectInputDate getSelectInputDate4() {
        return selectInputDate4;
    }

    public void setSelectInputDate5(CoreSelectInputDate selectInputDate5) {
        this.selectInputDate5 = selectInputDate5;
    }

    public CoreSelectInputDate getSelectInputDate5() {
        return selectInputDate5;
    }


    public void setObjectSpacer1(CoreObjectSpacer objectSpacer1) {
        this.objectSpacer1 = objectSpacer1;
    }

    public CoreObjectSpacer getObjectSpacer1() {
        return objectSpacer1;
    }

    public void setObjectSpacer2(CoreObjectSpacer objectSpacer2) {
        this.objectSpacer2 = objectSpacer2;
    }

    public CoreObjectSpacer getObjectSpacer2() {
        return objectSpacer2;
    }

    public void setSelectOneChoice1(CoreSelectOneChoice selectOneChoice1) {
        this.selectOneChoice1 = selectOneChoice1;
    }

    public CoreSelectOneChoice getSelectOneChoice1() {
        return selectOneChoice1;
    }

    public void setSelectItems1(UISelectItems selectItems1) {
        this.selectItems1 = selectItems1;
    }

    public UISelectItems getSelectItems1() {
        return selectItems1;
    }

    public String selectTemporada_action() {
         BindingContainer bindings = getBindings();
         OperationBinding operationBinding = bindings.getOperationBinding("setCurrentRowWithKey");
         Object result = operationBinding.execute();
         if (!operationBinding.getErrors().isEmpty()) {
           return null;
         }
        JSFUtils.setExpressionValue("#{bindings.showDetalle.inputValue}","1");
        JSFUtils.setExpressionValue("#{bindings.editable.inputValue}","1");
        return null;
    }

    public void setBindings(BindingContainer bindings) {
        this.bindings = bindings;
    }

    public BindingContainer getBindings() {
        return bindings;
    }

    public String eliminarTemporada_action() {
         BindingContainer bindings = getBindings();
         OperationBinding operationBinding = bindings.getOperationBinding("setCurrentRowWithKey");
         Object result = operationBinding.execute();
         if (!operationBinding.getErrors().isEmpty()) {
           return null;
         }
        operationBinding = bindings.getOperationBinding("Suprimir");
        result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
          return null;
        }
        getService().getDBTransaction().commit();
        JSFUtils.setExpressionValue("#{bindings.showDetalle.inputValue}","1");
        return null;
    }
    
    private AppModuleImpl getService(){
        FacesContext ctx = FacesContext.getCurrentInstance();
        
        //Creando el binding container 
        ValueBinding vb = ctx.getApplication().createValueBinding("#{data}");
        BindingContext bc = (BindingContext)vb.getValue(ctx);
        
        DCDataControl dc  = bc.findDataControl("AppModuleDataControl");
        ApplicationModule am = (ApplicationModule)dc.getDataProvider();
        return (AppModuleImpl)am;
    }

    public void setCommandButton2(CoreCommandButton commandButton2) {
        this.commandButton2 = commandButton2;
    }

    public CoreCommandButton getCommandButton2() {
        return commandButton2;
    }

    public void setCommandButton3(CoreCommandButton commandButton3) {
        this.commandButton3 = commandButton3;
    }

    public CoreCommandButton getCommandButton3() {
        return commandButton3;
    }

    public String agregarTemporada_action() {
         BindingContainer bindings = getBindings();
         OperationBinding operationBinding = 
             bindings.getOperationBinding("CrearInsercion");
         Object result = operationBinding.execute();
         if (!operationBinding.getErrors().isEmpty()) {
             return null;
         }
        
        AppModuleImpl service = getService();
        temporadaInscripcionViewImpl temporada = service.gettemporadaInscripcionView1();
        Row temporadaRow = temporada.getCurrentRow();
        temporadaRow.setAttribute("Anio",String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
        JSFUtils.setExpressionValue("#{bindings.showDetalle.inputValue}","1");
        JSFUtils.setExpressionValue("#{bindings.editable.inputValue}","0");
        return null;
    }

    public String Guardar_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("Commit");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        JSFUtils.setExpressionValue("#{bindings.showDetalle.inputValue}","0");
        return null;
    }

    public String Cancelar_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
            bindings.getOperationBinding("Rollback");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        JSFUtils.setExpressionValue("#{bindings.showDetalle.inputValue}","0");
        return null;
    }

    public void setOutputText1(CoreInputText outputText1) {
        this.outputText1 = outputText1;
    }

    public CoreInputText getOutputText1() {
        return outputText1;
    }

    public void setSelectInputDate6(CoreSelectInputDate selectInputDate6) {
        this.selectInputDate6 = selectInputDate6;
    }

    public CoreSelectInputDate getSelectInputDate6() {
        return selectInputDate6;
    }


    public void setTable1(CoreTable table1) {
        this.table1 = table1;
    }

    public CoreTable getTable1() {
        return table1;
    }


    public void setColumn2(CoreColumn column2) {
        this.column2 = column2;
    }

    public CoreColumn getColumn2() {
        return column2;
    }

    public void setOutputText3(CoreCommandLink outputText3) {
        this.outputText3 = outputText3;
    }

    public CoreCommandLink getOutputText3() {
        return outputText3;
    }


    public void setCommandButton1(CoreCommandButton commandButton1) {
        this.commandButton1 = commandButton1;
    }

    public CoreCommandButton getCommandButton1() {
        return commandButton1;
    }

    public void setPanelTip1(CorePanelTip panelTip1) {
        this.panelTip1 = panelTip1;
    }

    public CorePanelTip getPanelTip1() {
        return panelTip1;
    }

    public void setOutputText10(CoreOutputText outputText10) {
        this.outputText10 = outputText10;
    }

    public CoreOutputText getOutputText10() {
        return outputText10;
    }

    public void setPanelTip2(CorePanelTip panelTip2) {
        this.panelTip2 = panelTip2;
    }

    public CorePanelTip getPanelTip2() {
        return panelTip2;
    }

    public void setOutputText11(CoreOutputText outputText11) {
        this.outputText11 = outputText11;
    }

    public CoreOutputText getOutputText11() {
        return outputText11;
    }

    public void setColumn3(CoreColumn column3) {
        this.column3 = column3;
    }

    public CoreColumn getColumn3() {
        return column3;
    }

    public void setOutputText2(CoreOutputText outputText2) {
        this.outputText2 = outputText2;
    }

    public CoreOutputText getOutputText2() {
        return outputText2;
    }

    public void setColumn1(CoreColumn column1) {
        this.column1 = column1;
    }

    public CoreColumn getColumn1() {
        return column1;
    }

    public void setOutputText4(CoreOutputText outputText4) {
        this.outputText4 = outputText4;
    }

    public CoreOutputText getOutputText4() {
        return outputText4;
    }

    public void setColumn8(CoreColumn column8) {
        this.column8 = column8;
    }

    public CoreColumn getColumn8() {
        return column8;
    }

    public void setOutputText5(CoreOutputText outputText5) {
        this.outputText5 = outputText5;
    }

    public CoreOutputText getOutputText5() {
        return outputText5;
    }

    public void setColumn4(CoreColumn column4) {
        this.column4 = column4;
    }

    public CoreColumn getColumn4() {
        return column4;
    }

    public void setOutputText6(CoreOutputText outputText6) {
        this.outputText6 = outputText6;
    }

    public CoreOutputText getOutputText6() {
        return outputText6;
    }

    public void setColumn5(CoreColumn column5) {
        this.column5 = column5;
    }

    public CoreColumn getColumn5() {
        return column5;
    }

    public void setOutputText7(CoreOutputText outputText7) {
        this.outputText7 = outputText7;
    }

    public CoreOutputText getOutputText7() {
        return outputText7;
    }

    public void setColumn6(CoreColumn column6) {
        this.column6 = column6;
    }

    public CoreColumn getColumn6() {
        return column6;
    }

    public void setOutputText8(CoreOutputText outputText8) {
        this.outputText8 = outputText8;
    }

    public CoreOutputText getOutputText8() {
        return outputText8;
    }


    public void setColumn71(CoreColumn column71) {
        this.column71 = column71;
    }

    public CoreColumn getColumn71() {
        return column71;
    }

    public void setOutputText12(CoreOutputText outputText12) {
        this.outputText12 = outputText12;
    }

    public CoreOutputText getOutputText12() {
        return outputText12;
    }

    public void setColumn9(CoreColumn column9) {
        this.column9 = column9;
    }

    public CoreColumn getColumn9() {
        return column9;
    }

    public void setCommandLink1(CoreCommandLink commandLink1) {
        this.commandLink1 = commandLink1;
    }

    public CoreCommandLink getCommandLink1() {
        return commandLink1;
    }

    public String borrar_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = bindings.getOperationBinding("setCurrentRowWithKey");
        Object result = operationBinding.execute();
        operationBinding = bindings.getOperationBinding("Suprimir");
        result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        AppModuleImpl service = getService();
        service.getDBTransaction().commit();
        return null;
    }


}
